<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>阿里云文件在线编辑器</title>
    <style>
        #editor {
            width: 100%;
            height: 400px;
            font-family: monospace;
        }
    </style>
</head>
<body>
<h1>阿里云IMM在线编辑器</h1>
<textarea id="editor" name="editor"></textarea>
<button onclick="loadFile()">加载文件</button>
<button onclick="saveFile()">保存文件</button>
<script>
    const editor = document.getElementById('editor');
    const baseUrl = 'http://localhost:8080/oss'; // 根据实际情况修改URL

    function loadFile() {
        const fileName = 'test/osstest.txt';
        fetch(`${baseUrl}/downloadFile?osskey=${encodeURIComponent(fileName)}`)
            .then(response => response.text())
            .then(text => {
                editor.value = text;
            })
            .catch(error => {
                console.error('加载文件失败', error);
            });
    }

    function saveFile() {
        const fileName = 'test/osstest.txt';
        const content = editor.value;
        fetch(`${baseUrl}/saveFile?osskey=${encodeURIComponent(fileName)}`, {
            method: 'POST',
            headers: { 'Content-Type': 'text/plain' },
            body: content
        })
            .then(response => {
                if (response.ok) {
                    console.log('文件保存成功');
                } else {
                    throw new Error('保存失败');
                }
            })
            .catch(error => {
                console.error('保存失败', error);
            });
    }
</script>
</body>
</html>